SPB Git

Repository Public MIT

route.ts 1.1 KB 20 lines typescript

1import { join } from "node:path";2import { env } from "@/lib/env";3import { notFoundResponse, serveObject } from "@/lib/serve";4import { currentSession } from "@/lib/studio/guard";5import { getResource } from "@/server/content";6import { FsStorage } from "@/modules/storage";78export const dynamic = "force-dynamic";910/** Any version of a resource, for a signed-in editor (?version=N; the current one by default). */11export async function GET(request: Request, { params }: { params: Promise<{ session: string; resource: string }> }) {12  if (!(await currentSession())) return notFoundResponse();13  const { session, resource } = await params;14  let row;15  try { row = getResource(session, resource); } catch { return notFoundResponse(); }16  const wanted = Number(new URL(request.url).searchParams.get("version")) || row.currentVersion, v = row.versions.find((x) => x.version === wanted);17  if (!v) return notFoundResponse();18  return serveObject(new FsStorage(join(env.dataDir, "resources")), v.path, request, { cache: "private, no-store", download: v.filename, type: v.mime });19}20
Files main
Menu

Theme